﻿Imports System.Collections.Specialized
Imports System.Linq
Imports System.ComponentModel

Imports IntoNails.DataAccess
Imports IntoNails.Models

Namespace ViewModel
    Public Class NailServiceRepositoryViewModel
        Inherits SubWorkspaceViewModel

#Region "Fields"

        Private ReadOnly _repository As NailServiceRepository

#End Region

#Region "Constructors"

        Public Sub New(ByVal repository As NailServiceRepository)
            _repository = repository

            ' Subscribe for data notifications.

        End Sub

#End Region

#Region "Functions"

        Private Sub FillRepository()
            Dim items As List(Of NailServiceViewModel) = _
                (From nail In _repository.GetRawCollection() _
                 Select New NailServiceViewModel(nail, _repository)).ToList()

            For Each item In items
                AddHandler item.PropertyChanged, AddressOf Me.NailService_PropertyChanged
            Next
        End Sub

#End Region

#Region "Event Handlers"

        Private Sub OnCollectionChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)

        End Sub

        Private Sub NailService_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
            Dim IsSelected As String = "IsSelected"

            ' Make sure that the property name we're referencing is valid.
            ' This is a debugging technique, and does not execute in a Release build.
            TryCast(sender, NailServiceViewModel).VerifyPropertyName(IsSelected)

            ' When a customer is selected or unselected, we must let the
            ' world know that the TotalSelectedSales property has changed,
            ' so that it will be queried again for a new value.
            If e.PropertyName = IsSelected Then
                Me.OnPropertyChanged("TotalSelectedSales")
            End If
        End Sub

#End Region

    End Class
End Namespace
